import { InputNumber, Tooltip } from 'antd';
import { removeDateHmsStr, renderTableText, tableSorter } from '@/utils';
import pageStyles from '@/common/pageLayout.less';
import { DictionaryRenderFun, formatDecimal } from '../../Acommon';

/** 材料表格 */
const openMaterielColumns = () => {
  let tableConfig: Record<string, any>[] = [
    {
      title: '材料名称',
      dataIndex: 'assetName',
      key: 'assetName',
      width: 110,
      fixed: 'left',
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '材料编码',
      dataIndex: 'materialCode',
      key: 'materialCode',
      width: 110,
      fixed: 'left',
      sorter: (a: any, b: any) => tableSorter(a, b, 'materialCode'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '材料分类',
      dataIndex: 'assetClassName',
      key: 'assetClassName',
      width: 110,
      fixed: 'left',
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetClassName'),
      render: (text: number) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '规格型号',
      dataIndex: 'paramsInfo',
      key: 'paramsInfo',
      width: 160,
      sorter: (a: any, b: any) => tableSorter(a, b, 'paramsInfo'),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '数量',
      dataIndex: 'residueNum',
      key: 'residueNum',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'residueNum'),
      render: (text: number | null) => formatDecimal(text),
    },
    {
      title: '计量单位',
      dataIndex: 'unitOfMeasurementName',
      key: 'unitOfMeasurementName',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'unitOfMeasurementName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '单价（元）',
      dataIndex: 'assetValue',
      key: 'assetValue',
      width: 120,
      sorter: (a: any, b: any) => tableSorter(a, b, 'assetValue'),
      render: (text: number | null) => formatDecimal(text),
    },
    {
      title: '总价（元）',
      dataIndex: 'totalValue',
      key: 'totalValue',
      width: 120,
      sorter: (a: any, b: any) => tableSorter(a, b, 'totalValue'),
      render: (text: number | null) => formatDecimal(text),
    },
    {
      title: '品牌',
      dataIndex: 'brandType',
      key: 'brandType',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'brandType'),
      render: (text: string) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '取得日期',
      dataIndex: 'enterStoreTime',
      key: 'enterStoreTime',
      width: 150,
      sorter: (a: any, b: any) => tableSorter(a, b, 'enterStoreTime'),
      render: (text: string) => removeDateHmsStr(text) || '--',
    },
    {
      title: '使用期限',
      dataIndex: 'durableYears',
      key: 'durableYears',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'durableYears'),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '有效数量',
      dataIndex: 'validNum',
      key: 'validNum',
      width: 160,
      fixed: 'right',
      sorter: (a: any, b: any) => tableSorter(a, b, 'validNum'),
      render: (text: number | null) => formatDecimal(text),
    },
  ];

  return tableConfig;
};

/** 表格配置 */
const contractTableConfig = () => {
  let tableConfig: Record<string, any>[] = [
    {
      title: '合同编号',
      dataIndex: 'contractCode',
      key: 'contractCode',
      fixed: 'left',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'contractCode'),
      render: (text: string) => {
        return (
          <Tooltip title={text}>
            <div className={pageStyles['over-flow-hidden']}>{text || '--'}</div>
          </Tooltip>
        );
      },
    },
    {
      title: '合同名称',
      dataIndex: 'contractName',
      key: 'contractName',
      fixed: 'left',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'contractName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '合同金额',
      dataIndex: 'sumInTax',
      key: 'sumInTax',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'sumInTax'),
      render: (text: number | null) => formatDecimal(text),
    },
    {
      title: '资金来源编号',
      dataIndex: 'projectID',
      key: 'projectID',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'projectID'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '资金来源',
      dataIndex: 'projectName',
      key: 'projectName',
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'projectName'),
      render: (text: string) => renderTableText(text, true),
    },
    // {
    //   title: '合同签订时间',
    //   dataIndex: 'signTime',
    //   key: 'signTime',
    //   visible: true,
    //   width: 100,
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'signTime'),
    //   render: (text: number | any) => {
    //     return <span>{text ? text : '--'}</span>;
    //   },
    // },
    {
      title: '采购方式',
      dataIndex: 'procureRealName',
      key: 'procureRealName',
      visible: true,
      width: 100,
      sorter: (a: any, b: any) => tableSorter(a, b, 'procureRealName'),
      render: (text: string) => DictionaryRenderFun({ text, isState: false }),
    },
    {
      title: '有效金额',
      dataIndex: 'effectiveMoney',
      key: 'effectiveMoney',
      fixed: 'right',
      visible: true,
      width: 100,
      render: (value: number | any, record: Record<string, any>, index: number) => {
        return (
          <InputNumber
            value={value}
            bordered={false}
            style={{ width: '100%' }}
            onChange={(e) => {
              // changeContractData({ type: 'effectiveMoney', value: e, index });
            }}
            disabled={true}
            precision={2}
          />
        );
      },
    },
  ];
  return tableConfig;
};

export { openMaterielColumns, contractTableConfig };
